<?php
//Kiem tra xem co phai lay noi dung don tu ho so lien quan
	$v_xml_str_header = '<?xml version="1.0" encoding="UTF-8"?><root><data_list>';
	//Cong them gia tri cua xau chua so giay phep vao
	$v_xml_replace = $v_xml_str_header . '<relate_record>' . $v_relate_record_code .'</relate_record>';
	if (is_null($v_xml_str) || $v_xml_str==""){
		$v_xml_str = $v_xml_replace . '</data_list></root>';	
	}else{
		$v_xml_str = str_replace($v_xml_str_header,$v_xml_replace,$v_xml_str);
	}

//cac file chua cau truc cua bang
$v_folder = '001';
$v_bang = 'cau_truc_bang_don_xin_cap_phep.xml';
$v_dong = 'cac_dong_cua_don_xin_cap_phep.xml';
if(isset($_REQUEST['hdn_folder'])){
	$v_folder = $_REQUEST['hdn_folder'];
}
if(isset($_REQUEST['hdn_bang'])){
	$v_d_gp = $_REQUEST['hdn_bang'];
}
if($v_d_gp == 'd'){
	$v_bang = 'cau_truc_bang_don_xin_cap_phep.xml';
	$v_dong = 'cac_dong_cua_don_xin_cap_phep.xml';
}
else{
	$v_dong  = 'cac_dong_cua_noi_dung_giay_phep.xml';
	$v_bang= 'cau_truc_bang_noi_dung_giay_phep.xml';
}
$v_table_struct_xml_file = "../../xml/".$v_folder."/".$v_bang;//cau_truc_bang_don_xin_cap_phep.xml";
$v_formfield_xml_file = "../../xml/".$v_folder."/".$v_dong;//cac_dong_cua_don_xin_cap_phep.xml";
//echo $v_formfield_xml_file; exit;
$v_table_struct_xml_string = _read_file($v_table_struct_xml_file);
$v_formfield_xml_string = _read_file($v_formfield_xml_file);
//echo htmlspecialchars($v_formfield_xml_string);
//Doc va ghi ra tieu de cua form
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_table_struct_xml_string);
$table_struct_rax->record_delim = 'common_para';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
$table_struct_row = $table_struct_rec->getRow();
$v_form_title = $table_struct_row["form_title"];
$v_first_col_width = $table_struct_row["first_col_width"];
$v_second_col_width = (100-$v_first_col_width)."%";
$v_js_file_name = $table_struct_row["js_file_name"];
$v_js_function  = $table_struct_row["js_function"];
if (!is_null($v_title)&&($v_title!="")){
	$v_form_title = $v_title;
}
//Begin//Bang chua cac thanh phan cua form
$v_html_string = $v_html_string . "<table width='100%'  border='0' cellspacing='0' cellpadding='0'><tr>";
$v_html_string = $v_html_string . "<td class='large_title'>".$v_form_title."</td>";
$v_html_string = $v_html_string . "</tr></table>";
//Bang chua cac bin hidden
//Doc cac dong cua form	
$table_struct_rax = new RAX(); 
$table_struct_rec = new RAX(); 
$table_struct_rax->open($v_table_struct_xml_string);
$table_struct_rax->record_delim = 'row';
$table_struct_rax->parse();
$table_struct_rec = $table_struct_rax->readRecord(); 
//Bang chua cac dong cua form
	$v_html_string = $v_html_string . "<table width='100%'  border='1' cellspacing='0' cellpadding='0' class='form_table1'>";
	$v_html_string = $v_html_string . "<col width='30%'><col width='40%'><col width='15%'><col width='15%'";
while ($table_struct_rec) { 
	$table_struct_row = $table_struct_rec->getRow();
	$v_have_line_before = $table_struct_row["have_line_before"];
	$v_col_number = $table_struct_row["col_number"];
	$v_tag_list = $table_struct_row["tag_list"];
	$v_row_id = $table_struct_row["row_id"];
	$arr_tag = explode(",", $v_tag_list);
	//Bang chua mot dong cua form
	$v_html_table = "";
	$v_html_tag = "";			
	for($i=0;$i < sizeof($arr_tag);$i++){
		$formfield_rax = new RAX(); 
		$formfield_rec = new RAX(); 
		$formfield_rax->open($v_formfield_xml_string);
		$formfield_rax->record_delim = $arr_tag[$i];
		$formfield_rax->parse();
		$formfield_rec = $formfield_rax->readRecord(); 
		$formfield_row = $formfield_rec->getRow(); 
		$v_label = $formfield_row["label"];
		$v_type = $formfield_row["type"];
		$v_dataformat = $formfield_row["data_format"];
		$v_width = $formfield_row["width"];
		$v_row = $formfield_row["row"];
		$v_max = $formfield_row["max"];
		$v_min = $formfield_row["min"];
		$v_note = $formfield_row["note"];
		$v_tooltip = $formfield_row["tooltip"];
		$v_message = $formfield_row["message"];
		$v_optional = $formfield_row["optional"];
		$v_maxlength = $formfield_row["maxlength"];
		$v_xml_tag_in_db = $formfield_row["xml_tag_in_db"];
		//echo $v_xml_tag_in_db."<br>";
		$v_default_value = $formfield_row["default_value"];
		$v_js_function_list = $formfield_row["js_function_list"];
		$v_js_action_list = $formfield_row["js_action_list"];
		$v_relate_recordtype = $formfield_row["relate_recordtype"];
		$v_readonly_in_edit_mode = $formfield_row["readonly_in_edit_mode"];
		$v_disabled_in_edit_mode = $formfield_row["disabled_in_edit_mode"];
		if ($v_xml_str!=""){
			$column_rax = new RAX(); 
			$column_rec = new RAX();
			$column_rax->open($v_xml_str);
			$column_rax->record_delim = 'data_list';
			$column_rax->parse();
			$column_rec = $column_rax->readRecord(); 
			$column_row = $column_rec->getRow();
			$v_value = _restore_XML_bad_char($column_row[$v_xml_tag_in_db]); 
		}
		//Kiem tra neu gia tri DEFAULT  ton tai va gia tri cua truong do la bang rong thi thay the bang gia tri Default
		if($v_optional == 'false'){
			$v_optional = 'B&#7855;t bu&#7897;c';
		} else {
			$v_optional = '&nbsp;';
		}
		if($v_type != 'label'){
			$v_html_tag = $v_html_tag . "<tr id = '$v_row_id' style='display:block'><td class='normal_label'>".$v_xml_tag_in_db."</td>";		
			$v_html_tag = $v_html_tag . "<td class='normal_label'>".$v_label."</td>";
			$v_html_tag = $v_html_tag . "<td class='normal_label'>".$v_type."</td>";		
			$v_html_tag = $v_html_tag . "<td class='normal_label'>".$v_optional."</td></tr>";		
		}
	}
	$v_html_string = $v_html_string .  $v_html_table. $v_html_tag;
	$table_struct_rec = $table_struct_rax->readRecord();
}
$v_html_string = $v_html_string . "</table>";
$v_html_string = $v_html_string . '<script language="JavaScript">'.$v_js_function.'</script>';
//End//Bang chua cac thanh phan cua form
?><form name="hg" action="index.php">
<input type="hidden" name="hdn_folder" value="" />
<input type="hidden" name="hdn_bang" value="" />
<input type="hidden" name="fuseaction" value="DISPLAY_SINGLE_RECORD" />
<table width="100%">
<tr class="normal_label">
<td>Th&#432; m&#7909;c: <input type="textbox" width="10%" name = "folder" value="<?php echo $v_folder?>"/></td>
<td>&#272;&#417;n ho&#7863;c gi&#7845;y ph&#233;p: <input type="textbox" width="40%" name="bang" onblur="onchange_submit()" value="<?php echo $v_d_gp?>"/></td>
</tr>
</table>
<?php
echo $v_html_string;
?>
</form>
<script>
	document.forms(0).folder.focus() = true;
	function onchange_submit(){
		document.forms(0).hdn_folder.value = document.forms(0).folder.value;
		document.forms(0).hdn_bang.value = document.forms(0).bang.value;
		document.forms(0).submit();
	}
</script>